<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>8.9. unicodedata — Unicode Database &mdash; Python v2.6.2 documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '2.6.2',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v2.6.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v2.6.2 documentation" href="../index.html" />
    <link rel="up" title="8. String Services" href="strings.html" />
    <link rel="next" title="8.10. stringprep — Internet String Preparation" href="stringprep.html" />
    <link rel="prev" title="8.8. codecs — Codec registry and base classes" href="codecs.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="stringprep.html" title="8.10. stringprep — Internet String Preparation"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="8.8. codecs — Codec registry and base classes"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="strings.html" accesskey="U">8. String Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-unicodedata">
<h1>8.9. <tt class="xref docutils literal"><span class="pre">unicodedata</span></tt> &#8212; Unicode Database<a class="headerlink" href="#module-unicodedata" title="Permalink to this headline">¶</a></h1>
<p id="index-679">This module provides access to the Unicode Character Database which defines
character properties for all Unicode characters. The data in this database is
based on the <tt class="docutils literal"><span class="pre">UnicodeData.txt</span></tt> file version 5.1.0 which is publicly
available from <a class="reference external" href="ftp://ftp.unicode.org/">ftp://ftp.unicode.org/</a>.</p>
<p>The module uses the same names and symbols as defined by the UnicodeData File
Format 5.1.0 (see <a class="reference external" href="http://www.unicode.org/Public/5.1.0/ucd/UCD.html">http://www.unicode.org/Public/5.1.0/ucd/UCD.html</a>).  It defines
the following functions:</p>
<dl class="function">
<dt id="unicodedata.lookup">
<tt class="descclassname">unicodedata.</tt><tt class="descname">lookup</tt><big>(</big><em>name</em><big>)</big><a class="headerlink" href="#unicodedata.lookup" title="Permalink to this definition">¶</a></dt>
<dd>Look up character by name.  If a character with the given name is found, return
the corresponding Unicode character.  If not found, <a title="exceptions.KeyError" class="reference external" href="exceptions.html#exceptions.KeyError"><tt class="xref docutils literal"><span class="pre">KeyError</span></tt></a> is raised.</dd></dl>

<dl class="function">
<dt id="unicodedata.name">
<tt class="descclassname">unicodedata.</tt><tt class="descname">name</tt><big>(</big><em>unichr</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#unicodedata.name" title="Permalink to this definition">¶</a></dt>
<dd>Returns the name assigned to the Unicode character <em>unichr</em> as a string. If no
name is defined, <em>default</em> is returned, or, if not given, <a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is
raised.</dd></dl>

<dl class="function">
<dt id="unicodedata.decimal">
<tt class="descclassname">unicodedata.</tt><tt class="descname">decimal</tt><big>(</big><em>unichr</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#unicodedata.decimal" title="Permalink to this definition">¶</a></dt>
<dd>Returns the decimal value assigned to the Unicode character <em>unichr</em> as integer.
If no such value is defined, <em>default</em> is returned, or, if not given,
<a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</dd></dl>

<dl class="function">
<dt id="unicodedata.digit">
<tt class="descclassname">unicodedata.</tt><tt class="descname">digit</tt><big>(</big><em>unichr</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#unicodedata.digit" title="Permalink to this definition">¶</a></dt>
<dd>Returns the digit value assigned to the Unicode character <em>unichr</em> as integer.
If no such value is defined, <em>default</em> is returned, or, if not given,
<a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</dd></dl>

<dl class="function">
<dt id="unicodedata.numeric">
<tt class="descclassname">unicodedata.</tt><tt class="descname">numeric</tt><big>(</big><em>unichr</em><span class="optional">[</span>, <em>default</em><span class="optional">]</span><big>)</big><a class="headerlink" href="#unicodedata.numeric" title="Permalink to this definition">¶</a></dt>
<dd>Returns the numeric value assigned to the Unicode character <em>unichr</em> as float.
If no such value is defined, <em>default</em> is returned, or, if not given,
<a title="exceptions.ValueError" class="reference external" href="exceptions.html#exceptions.ValueError"><tt class="xref docutils literal"><span class="pre">ValueError</span></tt></a> is raised.</dd></dl>

<dl class="function">
<dt id="unicodedata.category">
<tt class="descclassname">unicodedata.</tt><tt class="descname">category</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.category" title="Permalink to this definition">¶</a></dt>
<dd>Returns the general category assigned to the Unicode character <em>unichr</em> as
string.</dd></dl>

<dl class="function">
<dt id="unicodedata.bidirectional">
<tt class="descclassname">unicodedata.</tt><tt class="descname">bidirectional</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.bidirectional" title="Permalink to this definition">¶</a></dt>
<dd>Returns the bidirectional category assigned to the Unicode character <em>unichr</em> as
string. If no such value is defined, an empty string is returned.</dd></dl>

<dl class="function">
<dt id="unicodedata.combining">
<tt class="descclassname">unicodedata.</tt><tt class="descname">combining</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.combining" title="Permalink to this definition">¶</a></dt>
<dd>Returns the canonical combining class assigned to the Unicode character <em>unichr</em>
as integer. Returns <tt class="docutils literal"><span class="pre">0</span></tt> if no combining class is defined.</dd></dl>

<dl class="function">
<dt id="unicodedata.east_asian_width">
<tt class="descclassname">unicodedata.</tt><tt class="descname">east_asian_width</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.east_asian_width" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the east asian width assigned to the Unicode character <em>unichr</em> as
string.</p>
<p>
<span class="versionmodified">New in version 2.4.</span></p>
</dd></dl>

<dl class="function">
<dt id="unicodedata.mirrored">
<tt class="descclassname">unicodedata.</tt><tt class="descname">mirrored</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.mirrored" title="Permalink to this definition">¶</a></dt>
<dd>Returns the mirrored property assigned to the Unicode character <em>unichr</em> as
integer. Returns <tt class="docutils literal"><span class="pre">1</span></tt> if the character has been identified as a &#8220;mirrored&#8221;
character in bidirectional text, <tt class="docutils literal"><span class="pre">0</span></tt> otherwise.</dd></dl>

<dl class="function">
<dt id="unicodedata.decomposition">
<tt class="descclassname">unicodedata.</tt><tt class="descname">decomposition</tt><big>(</big><em>unichr</em><big>)</big><a class="headerlink" href="#unicodedata.decomposition" title="Permalink to this definition">¶</a></dt>
<dd>Returns the character decomposition mapping assigned to the Unicode character
<em>unichr</em> as string. An empty string is returned in case no such mapping is
defined.</dd></dl>

<dl class="function">
<dt id="unicodedata.normalize">
<tt class="descclassname">unicodedata.</tt><tt class="descname">normalize</tt><big>(</big><em>form</em>, <em>unistr</em><big>)</big><a class="headerlink" href="#unicodedata.normalize" title="Permalink to this definition">¶</a></dt>
<dd><p>Return the normal form <em>form</em> for the Unicode string <em>unistr</em>. Valid values for
<em>form</em> are &#8216;NFC&#8217;, &#8216;NFKC&#8217;, &#8216;NFD&#8217;, and &#8216;NFKD&#8217;.</p>
<p>The Unicode standard defines various normalization forms of a Unicode string,
based on the definition of canonical equivalence and compatibility equivalence.
In Unicode, several characters can be expressed in various way. For example, the
character U+00C7 (LATIN CAPITAL LETTER C WITH CEDILLA) can also be expressed as
the sequence U+0327 (COMBINING CEDILLA) U+0043 (LATIN CAPITAL LETTER C).</p>
<p>For each character, there are two normal forms: normal form C and normal form D.
Normal form D (NFD) is also known as canonical decomposition, and translates
each character into its decomposed form. Normal form C (NFC) first applies a
canonical decomposition, then composes pre-combined characters again.</p>
<p>In addition to these two forms, there are two additional normal forms based on
compatibility equivalence. In Unicode, certain characters are supported which
normally would be unified with other characters. For example, U+2160 (ROMAN
NUMERAL ONE) is really the same thing as U+0049 (LATIN CAPITAL LETTER I).
However, it is supported in Unicode for compatibility with existing character
sets (e.g. gb2312).</p>
<p>The normal form KD (NFKD) will apply the compatibility decomposition, i.e.
replace all compatibility characters with their equivalents. The normal form KC
(NFKC) first applies the compatibility decomposition, followed by the canonical
composition.</p>
<p>Even if two unicode strings are normalized and look the same to
a human reader, if one has combining characters and the other
doesn&#8217;t, they may not compare equal.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<p>In addition, the module exposes the following constant:</p>
<dl class="data">
<dt id="unicodedata.unidata_version">
<tt class="descclassname">unicodedata.</tt><tt class="descname">unidata_version</tt><a class="headerlink" href="#unicodedata.unidata_version" title="Permalink to this definition">¶</a></dt>
<dd><p>The version of the Unicode database used in this module.</p>
<p>
<span class="versionmodified">New in version 2.3.</span></p>
</dd></dl>

<dl class="data">
<dt id="unicodedata.ucd_3_2_0">
<tt class="descclassname">unicodedata.</tt><tt class="descname">ucd_3_2_0</tt><a class="headerlink" href="#unicodedata.ucd_3_2_0" title="Permalink to this definition">¶</a></dt>
<dd><p>This is an object that has the same methods as the entire module, but uses the
Unicode database version 3.2 instead, for applications that require this
specific version of the Unicode database (such as IDNA).</p>
<p>
<span class="versionmodified">New in version 2.5.</span></p>
</dd></dl>

<p>Examples:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">import</span> <span class="nn">unicodedata</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">lookup</span><span class="p">(</span><span class="s">&#39;LEFT CURLY BRACKET&#39;</span><span class="p">)</span>
<span class="go">u&#39;{&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">name</span><span class="p">(</span><span class="s">u&#39;/&#39;</span><span class="p">)</span>
<span class="go">&#39;SOLIDUS&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">decimal</span><span class="p">(</span><span class="s">u&#39;9&#39;</span><span class="p">)</span>
<span class="go">9</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">decimal</span><span class="p">(</span><span class="s">u&#39;a&#39;</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
  File <span class="nb">&quot;&lt;stdin&gt;&quot;</span>, line <span class="m">1</span>, in <span class="n-Identifier">?</span>
<span class="nc">ValueError</span>: <span class="n-Identifier">not a decimal</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">category</span><span class="p">(</span><span class="s">u&#39;A&#39;</span><span class="p">)</span>  <span class="c"># &#39;L&#39;etter, &#39;u&#39;ppercase</span>
<span class="go">&#39;Lu&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">unicodedata</span><span class="o">.</span><span class="n">bidirectional</span><span class="p">(</span><span class="s">u&#39;</span><span class="se">\u0660</span><span class="s">&#39;</span><span class="p">)</span> <span class="c"># &#39;A&#39;rabic, &#39;N&#39;umber</span>
<span class="go">&#39;AN&#39;</span>
</pre></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h4>Previous topic</h4>
            <p class="topless"><a href="codecs.html"
                                  title="previous chapter">8.8. <tt class="docutils literal docutils literal docutils literal"><span class="pre">codecs</span></tt> &#8212; Codec registry and base classes</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="stringprep.html"
                                  title="next chapter">8.10. <tt class="docutils literal docutils literal docutils literal"><span class="pre">stringprep</span></tt> &#8212; Internet String Preparation</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/library/unicodedata.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="stringprep.html" title="8.10. stringprep — Internet String Preparation"
             >next</a> |</li>
        <li class="right" >
          <a href="codecs.html" title="8.8. codecs — Codec registry and base classes"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v2.6.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="strings.html" >8. String Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; <a href="../copyright.html">Copyright</a> 1990-2009, Python Software Foundation.
      Last updated on Apr 15, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.1.
    </div>
  </body>
</html>